/**
* <p><code>EaseFactory</code> A simple Factory for generating easing classes of a specified type.</p>
* 
* @author Jim Armstrong
* @version 1.0
*
* copyright (c) 2008, Jim Armstrong.  All Rights Reserved.
*
* This software program is supplied 'as is' without any warranty, express, implied, 
* or otherwise, including without limitation all warranties of merchantability or fitness
* for a particular purpose.  Jim Armstrong shall not be liable for any special incidental, or 
* consequential damages, including, without limitation, lost revenues, lost profits, or 
* loss of prospective economic advantage, resulting from the use or misuse of this software 
* program.
* 
*/

package singularity.easing;

  class EaseFactory implements IEasingFactory {
    // direct references to specific ease classes
    
    public var easeClass(getEaseClass, null) : IEasing ;
    public var easeType(default, setEaseType) : String ;
    // direct references to specific ease classes
    var __back:Back;
    var __bounce:Bounce;
    var __circular:Circular;
    var __cubic:Cubic;
    var __elastic:Elastic;
    var __exponential:Exponential;
    var __linear:Linear;
    var __none:None;
    var __quadratic:Quadratic;
    var __quartic:Quartic;
    var __qIntic:QIntic;
    var __sine:Sine;
    
    // reference to current easing class
    var __easeClass:IEasing;
    var __easeType:String;
    
    public function new(){
      //super();
      
      __easeType = Easing.NONE;
      
      __none        = new None();
      __easeClass   = __none;
      
      __back        = null;
      __bounce      = null;
      __circular    = null;
      __cubic       = null;
      __elastic     = null;
      __exponential = null;
      __linear      = null;
      __quadratic   = null;
      __quartic     = null;
      __qIntic     = null;
      __sine        = null;
    }
    
    // allow caller to work with a direct reference to the easing class
    public function getEaseClass():IEasing { return __easeClass; }
    
    // set the current ease reference from a pool with instances created just-in-tim
    public function setEaseType(_eType:String):String { 
      switch( _eType )
      {
        case Easing.BACK:
          if( __back == null )
            __back = new Back();
            
          __easeClass = __back;
        
        case Easing.BOUNCE:
          if( __bounce == null )
            __bounce = new Bounce();
            
          __easeClass = __bounce;  
        
        case Easing.CIRCULAR:
          if( __circular == null )
            __circular = new Circular();
            
          __easeClass = __circular;  
        
        case Easing.CUBIC:
          if( __cubic == null )
            __cubic = new Cubic();
            
          __easeClass = __cubic;  
        
        case Easing.ELASTIC:
          if( __elastic == null )
            __elastic = new Elastic();
            
          __easeClass = __elastic;  
        
        case Easing.EXPONENTIAL:
          if( __exponential == null )
            __exponential = new Exponential();
            
          __easeClass = __exponential;  
        
        case Easing.LINEAR:
          if( __linear == null )
            __linear = new Linear();
            
          __easeClass = __linear;  
        
        case Easing.NONE:
          if( __none == null )
            __none = new None();
            
          __easeClass = __none;  
        
        case Easing.QUADRATIC:
          if( __quadratic == null )
            __quadratic = new Quadratic();
            
          __easeClass = __quadratic;  
        
        case Easing.QIntIC:
          if( __qIntic == null )
            __qIntic = new QIntic();
            
          __easeClass = __qIntic;  
        
        case Easing.SINE:
          if( __sine == null )
            __sine = new Sine();
            
          __easeClass = __sine;  
        
        default:
          if( __none == null )
            __none = new None();
            
          __easeClass = __none;  
        
      }
    	return _eType; 
     }
    
    //public function getEaseType():String { return __easeType; }
    
    public function easeIn (t:Float, b:Float, c:Float, d:Float, ?optional1:Float=0, ?optional2:Float=0):Float 
	  {
      return __easeClass != null ? __easeClass.easeIn(t, b, c, d, optional1, optional2) : 0;
	  }
	   
	  public function easeOut (t:Float, b:Float, c:Float, d:Float, ?optional1:Float=0, ?optional2:Float=0):Float 
	  { 
	    return __easeClass != null ? __easeClass.easeOut(t, b, c, d, optional1, optional2) : 0;
	  }
	   
    public function easeInOut (t:Float, b:Float, c:Float, d:Float, ?optional1:Float=0, ?optional2:Float=0):Float 
	  {
		  return __easeClass != null ? __easeClass.easeInOut(t, b, c, d, optional1, optional2) : 0;
	  }
	}
